package relu.R.landscape;
import java.util.*;
import jfm.utils.*;

public class LSMap {
	ArrayList<double[]> points=new ArrayList<double[]>();
	public void addPoint(double x,double y, double z){
		points.add(new double[]{x,y,z});
	}
	public double[][] getPoints(){
		double[][] pointsArray=new double[3][points.size()];
		for(int i=0;i<points.size();i++){
			for(int j=0;j<3;j++){
				pointsArray[j][i]=points.get(i)[j];
			}
		}
		return pointsArray;
	}
	
	public double[][] toImage(double boxl,int grid){
		double[][] image=new double[grid][grid];
		JFMMath.doubleZero(image);
		double[] bins=new double[grid+1];
		bins[0]=0;
		double delta=boxl/grid;
		for(int i=0;i<grid;i++){
			bins[i+1]=bins[i]+delta;
		}
		for(double[] p:points){
			int xbin=(int)Math.floor(p[0]/delta);
			int ybin=(int)Math.floor(p[1]/delta);
			image[xbin][ybin]+=1;
		}		
		return image;
	}
}
